﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ebusiness_Domain.Model;
//using Ebusiness_Domain.Repository;
using Ebusiness_Domain.IRepository;
using Ebusiness_Domain.DomainService;
using AbpVnext_Module;

namespace Ebusiness_Application
{
    /// <summary>
    ///  1、应用服务AppService
    ///  2、数据传输对象Dto
    ///  3、工作单元UnitOfWork 
    ///  
    /// 用户页面直接操作Service
    /// </summary>
    public class ProductAppService : IProductAppService
    {
        /// <summary>
        /// 依赖仓储层
        /// </summary>
        public IProductRepository ProductRepository { get; set; }

        public ProductAppService(IProductRepository productRepository, ProductMannage productMannage)
        {
            ProductRepository = productRepository;
            this.productMannage = productMannage;
        }

        /// <summary>
        /// 依赖领域服务
        /// </summary>
        public ProductMannage productMannage { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="inserProductDto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public ProductDto InsertProduct(InserProductDto inserProductDto)
        {
            //dto转换
            Product product = new Product();
            product.ProductName = inserProductDto.ProductName;
            #region 添加商品-无逻辑,调用仓储层存储
            {
                //商品价格不能高于99999  手机端
                if (product.ProductPrice > 9999)
                {
                    throw new Exception("商品价格不能高于99999");
                }
                ProductRepository.InsertProduct(product);
            }
            #endregion

            #region  添加商品-有逻辑,调用领域服务进行业务逻辑处理(判断数据是否规范，比如名字、价格)、在存储
            {
                //productMannage.InsertProduct(product);
            }
            #endregion
            //返回结果给展现层 返回值 PC端返回两个值
            return new ProductDto();
        }
    }
}
